#! /bin/bash
CODE_BASE_DIR=/root/code/matecloud-v1/
NAME_GATEWAY=mate-gateway
NAME_UAA=mate-uaa
NAME_SYSTEM=mate-platform/mate-system
NAME_SYSTEM_NAME=mate-system
NAME_COMPONENT=mate-platform/mate-component
NAME_COMPONENT_NAME=mate-component


echo "pull code..."
cd ${CODE_BASE_DIR}
echo "checkout code..."

#git checkout dev
#git pull origin dev
#git checkout test
#git merge dev
#git push origin test

echo "maven clean install..."
mvn clean install -Dmaven.javadoc.skip=true -Dgpg.skip

##docker打包镜像

cd ${CODE_BASE_DIR}/${NAME_GATEWAY}/
echo "begin build gateway images..."
mvn package docker:build -Dmaven.test.skip=true
echo "success build gateway images..."

cd ${CODE_BASE_DIR}/${NAME_UAA}/
echo "begin build uaa images..."
mvn package docker:build -Dmaven.test.skip=true
echo "success build uaa images..."

cd ${CODE_BASE_DIR}/${NAME_SYSTEM}/
echo "begin build system images..."
mvn package docker:build -Dmaven.test.skip=true
echo "success build system images..."

cd ${CODE_BASE_DIR}/${NAME_COMPONENT}/
echo "begin build component images..."
mvn package docker:build -Dmaven.test.skip=true
echo "success build component images..."


### push镜像到仓库

# docker push registry.cn-hangzhou.aliyuncs.com/matecloud/mate-uaa:2.3.8-SNAPSHOT

### TODO rm杀死本地镜像，重启新的镜像 根据每个镜像分别启动

## 判断进项是否存在，如存在就stop,然后rmi

# 启动镜像

# docker run -it -d -p 10001:10001 -e "SPRING_PROFILES_ACTIVE=prod" --name $NAME_GATEWAY registry.cn-hangzhou.aliyuncs.com/matecloud/mate-gateway:2.3.8-SNAPSHOT
# docker run -it -d -p 20001:20001 -e "SPRING_PROFILES_ACTIVE=prod" --name $NAME_UAA registry.cn-hangzhou.aliyuncs.com/matecloud/mate-uaa:2.3.8-SNAPSHOT
# docker run -it -d -p 20002:20002 -e "SPRING_PROFILES_ACTIVE=prod" --name $NAME_SYSTEM_NAME registry.cn-hangzhou.aliyuncs.com/matecloud/mate-system:2.3.8-SNAPSHOT
# docker run -it -d -p 20003:20003 -e "SPRING_PROFILES_ACTIVE=prod" --name $NAME_COMPONENT_NAME registry.cn-hangzhou.aliyuncs.com/matecloud/mate-component:2.3.8-SNAPSHOT